/*
 * Questa classe rappresenta un link logico.
 * Un link logico è un collegamento (1 o più hop) tra 2 AS non obbligatoriamente adiacenti
 */

using namespace std;

class LogicalLink
{
    private:
	int ASOrigin;           //uso un intero che sarebbe l'indice del vettore degli AS,
	int ASDestination;      //non metto direttamente l'oggetto AS, che creerebbe ridondanza
	list <int> ASPath;
	int bandwidth;
    int latency;
	bool state;

	public:
	LogicalLink();
	LogicalLink(int ASOrigin, int ASDestination, int bandwidth, int latency, bool state);
	int getASOrigin();
	int getASDestination();
	list<int> getASPath();
	list< pair<int,int> > getASPathPair();
	bool setASPath(list<int> ASPath);
	int getBandwidth();
	bool setBandwidth(int bandwidth);
	int getLatency();
	bool setLatency(int latency);
	bool getState();
	bool setState(bool state);
	bool isASInASPath(int number);
	bool isLinkInASPath(int i, int j);
};

LogicalLink::LogicalLink()
{;}

LogicalLink::LogicalLink(int ASOrigin, int ASDestination, int bandwidth, int latency, bool state)
{
	this->ASOrigin = ASOrigin;
    this->ASDestination = ASDestination;
    this->bandwidth = bandwidth;
	this->latency = latency;
    this->state = state;
}

int LogicalLink::getASOrigin()
{
    return this->ASOrigin;
}

int LogicalLink::getASDestination()
{
    return this->ASDestination;
}

list<int> LogicalLink::getASPath()
{
    return this->ASPath;
}

bool LogicalLink::setASPath(list<int> ASPath)
{
    this->ASPath = ASPath;
}

list< pair<int,int> > LogicalLink::getASPathPair()
{
    //cout << "LogicalLink::getASPathPair"<<endl;
    int origin;
    int destination;
    list< pair<int, int> > lista;

    list<int>::iterator it;
    list<int>::iterator fine = ASPath.end();
    advance(fine,-1);

    for (it = ASPath.begin(); it != fine;)
    {
        //cout << *it << " ";
        origin = *it;
        it++;
        destination = *it;
        //cout << "inserisco la coppia "<<origin<<" "<<destination<<endl;
        lista.push_back(make_pair (origin,destination));
    }

    //cout << "esco da getASPathPair()"<<endl;

    return lista;
}


int LogicalLink::getBandwidth()
{
    return this->bandwidth;
}

bool LogicalLink::setBandwidth(int bandwidth)
{
    this->bandwidth = bandwidth;
}

int LogicalLink::getLatency()
{
    return this->latency;
}

bool LogicalLink::setLatency(int latency)
{
    this->latency = latency;
}

bool LogicalLink::getState()
{
    return this->state;
}

bool LogicalLink::setState(bool state)
{
    this->state = state;
}

bool LogicalLink::isASInASPath(int number)
{
    list< int >::iterator it;

    for (it = ASPath.begin(); it != ASPath.end(); it++)
    {
        if ((*it) == number)
            return true;
    }
    return false;
}

bool LogicalLink::isLinkInASPath(int i, int j)
{
    list< pair<int, int> > ASPathPair = getASPathPair();
    list< pair<int, int> >::iterator it;
    int origine;
    int destinazione;

    for (it = ASPathPair.begin(); it != ASPathPair.end(); it++)
    {
        pair<int,int> coppia = *it;
        origine = coppia.first;
        destinazione = coppia.second;
        if ((origine==i && destinazione==j) || (origine==j && destinazione==i))
            return true;
    }
    return false;
}

